package com.eber.demo.design.factory.method;

interface Car {
    void drive();
}

class BmwCar implements Car {
    @Override
    public void drive() {
        System.out.println("Driving Bmw.");
    }
}

class AudiCar implements Car {
    @Override
    public void drive() {
        System.out.println("Driving Audi.");
    }
}

interface CarFactory {
    Car getCar();
}

class BmwCarFactory implements CarFactory {
    @Override
    public Car getCar() {
        return new BmwCar();
    }
}

class AudiCarFactory implements CarFactory {
    @Override
    public Car getCar() {
        return new AudiCar();
    }
}

// ======================================================================

public class FactoryMethod {
    public static void main(String[] args) {
        CarFactory factory = new BmwCarFactory();
        factory.getCar().drive();
        factory = new AudiCarFactory();
        factory.getCar().drive();
    }
}
